package com.zxj.test.controller;

import com.zxj.test.common.api.Response;
import com.zxj.test.common.exception.SmsSendFailureException;
import com.zxj.test.service.SmsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zxj
 * @date 2020/7/18
 */
@RequestMapping("/sms")
@RestController
public class SmsController {

    @Autowired
    private SmsService smsService;

    @GetMapping("/send")
    public Response<Void> send(@RequestParam("mobile") String mobile) {
        boolean flag = smsService.sendVerificationCode(mobile);
        if (!flag) {
            throw new SmsSendFailureException("短信发送失败");
        }
        return Response.ok();
    }
}
